package com.example.graduate.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.graduate.conf.webSocket.WebSocketServer;
import com.example.graduate.dto.RemoteOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class WebSocketController {

    @RequestMapping(value = "/operation/{vmc}/{cmd}")
    public String remote(@PathVariable("vmc") long vmc, @PathVariable("cmd") String cmd) {
        System.out.print("remote");
        RemoteOperation operation = new RemoteOperation();
        operation.setDeclare("您的订单已被接单");
        operation.setOrderType("1");

        String message = JSONObject.toJSONString(operation);
        System.out.println("message in json is :" + message);
        return WebSocketServer.sendMessage(message, vmc);
    }

}